<!--
 * @Author: Zhouxin 2201_75539691@noreply.gitcode.com
 * @Date: 2024-11-21 16:39:08
 * @LastEditors: Zhouxin 2201_75539691@noreply.gitcode.com
 * @LastEditTime: 2024-11-21 16:39:17
 * @FilePath: \2024.11.21-day09-字符串方法 函数\test2.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

var plants = '西红柿,黄瓜,芹菜,豆角,土豆,黄瓜'; //length 18

console.log(plants.indexOf('黄瓜')); 
//4

console.log(plants.indexOf('黄瓜',5)); 
//16

console.log(plants.indexOf('黄')); 
//4

console.log(plants.indexOf('黄瓶')); 
//-1

console.log(plants.indexOf('大象')); 
//-1

console.log(plants.indexOf('')); 
//0


console.log(plants.indexOf('',5)); 
//5

console.log(plants.indexOf('',19)); 
//18 超出长度的参数会返回长度
    </script>
</body>
</html>